package com.zhangmeng.online.exam.entity;

import com.zhangmeng.online.exam.entity.baseEntity.BaseEntity;
import lombok.*;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author zm
 * @date 2025/2/28 14:46
 * @version: 1.0
 */
@NoArgsConstructor
@ToString(exclude = {"roles"})
@Getter
@Setter
@AllArgsConstructor
@Entity
@Table(name = "permission")
public class Permission extends BaseEntity<Long> {


    private String name;

    private String icon;

    private String url;

    private String description;

    private Integer sort;

    @Column(name = "frontpath")
    private String frontpath;

    @ManyToMany(mappedBy = "permissions",targetEntity = Role.class)
    private Set<Role> roles = new HashSet<>();

    @ManyToOne(fetch = FetchType.LAZY)
    private Permission parent;

    @OneToMany(mappedBy = "parent",fetch = FetchType.LAZY)
    private List<Permission> children = new ArrayList<>();

}
